package com.donkor.deepnight.utils

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.load.model.Headers
import com.guoqi.keepsign.R


class ImageLoadUtils {
    companion object {

        fun display(context: Context?, imageView: ImageView?, url: String?) {
            if (imageView == null) {
                throw IllegalArgumentException("argument error")
            }
            val glideUrl = GlideUrl(url, Headers {
                val header = HashMap<String, String>()
                header["cookie"] = "Hm_lvt_dbc355aef238b6c32b43eacbbf161c3c=1536981553; Hm_lpvt_dbc355aef238b6c32b43eacbbf161c3c=1536986863"
                header["Referer"] = url.toString()
                header
            })
            Glide.with(context).load(glideUrl)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .placeholder(R.mipmap.ic_image_loading)
                    .error(com.guoqi.keepsign.R.mipmap.ic_image_loading)
                    .crossFade().into(imageView)
        }

        fun displayHigh(context: Context?, imageView: ImageView?, url: String?) {
            if (imageView == null) {
                throw IllegalArgumentException("argument error")
            }
            Glide.with(context).load(url)
                    .asBitmap()
                    .format(DecodeFormat.PREFER_ARGB_8888)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .placeholder(com.guoqi.keepsign.R.mipmap.ic_image_loading)
                    .error(com.guoqi.keepsign.R.mipmap.ic_empty_picture)
                    .into(imageView)
        }
    }
}